// Copyright 2011 George Cook
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#import "BaseTest.h"
#import "Injective.h"
#import "InjectiveContextXMLFactory.h"
#import "InjectiveObjectDescription.h"
#import "InjectivePropertyDescription.h"
#import "InjectivePropertyValueDescription.h"
@interface InjectivePrimitivePropertyValueXMLFactoryTest : BaseTest
{
	InjectiveContextXMLFactory *factory;
}
@end

@implementation InjectivePrimitivePropertyValueXMLFactoryTest
- (void)setUp
{
	factory = [[InjectiveContextXMLFactory alloc] init];
}

- (void)tearDown
{
	[factory release], factory = nil;
}

- (void)testStringValue
{
	NSArray *descriptions = [factory processXMLFile:@"testStringValue.xml"];
	GHAssertNotNil(descriptions, @"no descriptions were generated");
	InjectiveObjectDescription *description = [descriptions lastObject];
	GHAssertNotNil(description.propertyDescriptions, @"there were no property descriptions");
	GHAssertTrue(1 == description.propertyDescriptions.count, @"didn't create 1 property, created %d", description.propertyDescriptions.count);
	InjectivePropertyDescription *propertyDescription = [description.propertyDescriptions lastObject];
	GHAssertTrue([propertyDescription.type isEqualToString:@"String"],@"didn't detect correct type");
	GHAssertTrue([propertyDescription.propertyName isEqualToString:@"stringValue"],@"didn't detect correct property name");
	InjectivePropertyValueDescription *valueDescription = propertyDescription.value;
	GHAssertNotNil(valueDescription,@"value wasn't set");
	GHAssertTrue(valueDescription.class == [InjectivePropertyValueDescription class],@"was not a primitve class");
	GHAssertTrue([valueDescription.propertyValueText isEqualToString:@"aString"],@"didn't set propertyvalue text");
	GHAssertTrue([valueDescription.type isEqualToString:@"String"],@"didn't set propertyvalue type");
}

- (void)testIntegerValue
{
	NSArray *descriptions = [factory processXMLFile:@"testIntegerValue.xml"];
	GHAssertNotNil(descriptions, @"no descriptions were generated");
	InjectiveObjectDescription *description = [descriptions lastObject];
	GHAssertNotNil(description.propertyDescriptions, @"there were no property descriptions");
	GHAssertTrue(1 == description.propertyDescriptions.count, @"didn't create 1 property, created %d", description.propertyDescriptions.count);
	InjectivePropertyDescription *propertyDescription = [description.propertyDescriptions lastObject];
	GHAssertTrue([propertyDescription.type isEqualToString:@"Integer"],@"didn't detect correct type");
	GHAssertTrue([propertyDescription.propertyName isEqualToString:@"integerValue"],@"didn't detect correct property name");
	InjectivePropertyValueDescription *valueDescription = propertyDescription.value;
	GHAssertNotNil(valueDescription,@"value wasn't set");
	GHAssertTrue(valueDescription.class == [InjectivePropertyValueDescription class],@"was not a primitve class");
	GHAssertTrue([valueDescription.propertyValueText isEqualToString:@"21"],@"didn't set propertyvalue text");
	GHAssertTrue([valueDescription.type isEqualToString:@"Integer"],@"didn't set propertyvalue type");
}

- (void)testFloatValue
{
	NSArray *descriptions = [factory processXMLFile:@"testFloatValue.xml"];
	GHAssertNotNil(descriptions, @"no descriptions were generated");
	InjectiveObjectDescription *description = [descriptions lastObject];
	GHAssertNotNil(description.propertyDescriptions, @"there were no property descriptions");
	GHAssertTrue(1 == description.propertyDescriptions.count, @"didn't create 1 property, created %d", description.propertyDescriptions.count);
	InjectivePropertyDescription *propertyDescription = [description.propertyDescriptions lastObject];
	GHAssertTrue([propertyDescription.type isEqualToString:@"Float"],@"didn't detect correct type");
	GHAssertTrue([propertyDescription.propertyName isEqualToString:@"floatValue"],@"didn't detect correct property name");
	InjectivePropertyValueDescription *valueDescription = propertyDescription.value;
	GHAssertNotNil(valueDescription,@"value wasn't set");
	GHAssertTrue(valueDescription.class == [InjectivePropertyValueDescription class],@"was not a primitve class");
	GHAssertTrue([valueDescription.propertyValueText isEqualToString:@"21.2"],@"didn't set propertyvalue text");
	GHAssertTrue([valueDescription.type isEqualToString:@"Float"],@"didn't set propertyvalue type");
}

- (void)testBoolValue
{
	NSArray *descriptions = [factory processXMLFile:@"testBoolValue.xml"];
	GHAssertNotNil(descriptions, @"no descriptions were generated");
	InjectiveObjectDescription *description = [descriptions lastObject];
	GHAssertNotNil(description.propertyDescriptions, @"there were no property descriptions");
	GHAssertTrue(1 == description.propertyDescriptions.count, @"didn't create 1 property, created %d", description.propertyDescriptions.count);
	InjectivePropertyDescription *propertyDescription = [description.propertyDescriptions lastObject];
	GHAssertTrue([propertyDescription.type isEqualToString:@"Boolean"],@"didn't detect correct type");
	GHAssertTrue([propertyDescription.propertyName isEqualToString:@"boolValue"],@"didn't detect correct property name");
	InjectivePropertyValueDescription *valueDescription = propertyDescription.value;
	GHAssertNotNil(valueDescription,@"value wasn't set");
	GHAssertTrue(valueDescription.class == [InjectivePropertyValueDescription class],@"was not a primitve class");
	GHAssertTrue([valueDescription.propertyValueText isEqualToString:@"True"],@"didn't set propertyvalue text");
	GHAssertTrue([valueDescription.type isEqualToString:@"Boolean"],@"didn't set propertyvalue type");
}
@end
